package com.seed.core.converter;

import cn.hutool.core.util.StrUtil;
import com.seed.core.column.*;
import com.seed.core.configuration.ColumnConfiguration1;
import com.seed.core.enumeration.ColumnType;
import com.seed.util.StrKit;
import com.seed.util.ThrowKit;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import static com.seed.core.column.DateTimeColumn.FORMAT;

public class ColumnConverter {

    public static Column toColumn(ColumnConfiguration1 configuration) {
        ColumnType type = configuration.getType();
        if(type == null) ThrowKit.exception("列类型必须配置");

        return switch (type) {
            case VARCHAR -> toVarcharColumn(configuration);
            case CHAR -> toCharColumn(configuration);
            case TINYTEXT -> toTinyTextColumn(configuration);
            case TEXT -> toTextColumn(configuration);
            case MEDIUMTEXT -> toMediumTextColumn(configuration);
            case LONGTEXT -> toLongTextColumn(configuration);
            case TINYINT -> toTinyIntColumn(configuration);
            case SMALLINT -> toSmallntColumn(configuration);
            case MEDIUMINT -> toMediumIntColumn(configuration);
            case INT -> toIntColumn(configuration);
            case BIGINT -> toBigIntColumn(configuration);
            case DOUBLE -> toDoubleColumn(configuration);
            case FLOAT -> toFloatColumn(configuration);
            case DECIMAL -> toDecimalColumn(configuration);
            case BIT -> toBitColumn(configuration);
            case ENUM -> toEnumColumn(configuration);
            case SET -> toSetColumn(configuration);
            case DATE -> toDateColumn(configuration);
            case YEAR -> toYearColumn(configuration);
            case DATETIME -> toDateTimeColumn(configuration);
            case TIMESTAMP -> toTimestampColumn(configuration);
            case FILE -> toFileColumn(configuration);
            case IMAGE -> toImageColumn(configuration);
            case AVATAR -> toAvatarColumn(configuration);
            case PASSWORD -> toPasswordColumn(configuration);
            case SALT -> toSaltColumn(configuration);
            case ICON -> toIconColumn(configuration);
            case QRCODE -> toQrCodeColumn(configuration);
            case TINYBLOB -> toTinyBlobColumn(configuration);
            case BLOB -> toBlobColumn(configuration);
            case MEDIUMBLOB -> toMediumBlobColumn(configuration);
            case LONGBLOB -> toLongBlobColumn(configuration);
            case BINARY -> toBinaryColumn(configuration);
            case VARBINARY -> toVarBinaryColumn(configuration);
            case JSON -> toJsonColumn(configuration);
            case COLOR -> toColorColumn(configuration);
            case REF -> toRefColumn(configuration);
            case YESNO -> toYesnoColumn(configuration);
            case SEX -> toSexColumn(configuration);
            case AGE -> toAgeColumn(configuration);
        };
    }

    private static void setBase(Column column, ColumnConfiguration1 configuration) {
        column.setLength(configuration.getLength());
        column.setLabel(configuration.getLabel());
        column.setComment(configuration.getComment());
        column.setRequired(configuration.getRequired());
        column.setUnique(configuration.getUnique());
        column.setOnInsertValue(configuration.getOnInsertValue());
        column.setOnUpdateValue(configuration.getOnUpdateValue());
//        column.setTypeHandler(typeHandler);TODO
    }

    private static VarcharColumn toVarcharColumn(ColumnConfiguration1 configuration) {
        VarcharColumn column = new VarcharColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static CharColumn toCharColumn(ColumnConfiguration1 configuration) {
        CharColumn column = new CharColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        return column;
    }

    private static TinyTextColumn toTinyTextColumn(ColumnConfiguration1 configuration) {
        TinyTextColumn column = new TinyTextColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static TextColumn toTextColumn(ColumnConfiguration1 configuration) {
        TextColumn column = new TextColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static MediumTextColumn toMediumTextColumn(ColumnConfiguration1 configuration) {
        MediumTextColumn column = new MediumTextColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static LongTextColumn toLongTextColumn(ColumnConfiguration1 configuration) {
        LongTextColumn column = new LongTextColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Long.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Long.valueOf(max));

        return column;
    }

    private static TinyIntColumn toTinyIntColumn(ColumnConfiguration1 configuration) {
        TinyIntColumn column = new TinyIntColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static SmallntColumn toSmallntColumn(ColumnConfiguration1 configuration) {
        SmallntColumn column = new SmallntColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static MediumIntColumn toMediumIntColumn(ColumnConfiguration1 configuration) {
        MediumIntColumn column = new MediumIntColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static IntColumn toIntColumn(ColumnConfiguration1 configuration) {
        IntColumn column = new IntColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static BigIntColumn toBigIntColumn(ColumnConfiguration1 configuration) {
        BigIntColumn column = new BigIntColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(BigInteger.valueOf(Long.parseLong(defVal)));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(BigInteger.valueOf(Long.parseLong(min)));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(BigInteger.valueOf(Long.parseLong(max)));

        return column;
    }

    private static DoubleColumn toDoubleColumn(ColumnConfiguration1 configuration) {
        DoubleColumn column = new DoubleColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Double.parseDouble(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Double.parseDouble(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Double.parseDouble(max));

        Map<String, Object> params = configuration.getParams();
        if(params != null) {
            Object precision = params.get("precision");
            if(StrUtil.isNotBlank((CharSequence) precision)) {
                column.setPrecision(Integer.valueOf((String) precision));
            }

            Object scale = params.get("scale");
            if(StrUtil.isNotBlank((CharSequence) scale)) {
                column.setScale(Integer.valueOf((String) scale));
            }
        }

        return column;
    }

    private static FloatColumn toFloatColumn(ColumnConfiguration1 configuration) {
        FloatColumn column = new FloatColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Float.parseFloat(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Float.parseFloat(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Float.parseFloat(max));

        Map<String, Object> params = configuration.getParams();
        if(params != null) {
            Object precision = params.get("precision");
            if(StrUtil.isNotBlank((CharSequence) precision)) {
                column.setPrecision(Integer.valueOf((String) precision));
            }

            Object scale = params.get("scale");
            if(StrUtil.isNotBlank((CharSequence) scale)) {
                column.setScale(Integer.valueOf((String) scale));
            }
        }

        return column;
    }

    private static DecimalColumn toDecimalColumn(ColumnConfiguration1 configuration) {
        DecimalColumn column = new DecimalColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(new BigDecimal(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(new BigDecimal(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(new BigDecimal(max));

        Map<String, Object> params = configuration.getParams();
        if(params != null) {
            Object precision = params.get("precision");
            if(StrUtil.isNotBlank((CharSequence) precision)) {
                column.setPrecision(Integer.valueOf((String) precision));
            }

            Object scale = params.get("scale");
            if(StrUtil.isNotBlank((CharSequence) scale)) {
                column.setScale(Integer.valueOf((String) scale));
            }
        }

        return column;
    }

    private static BitColumn toBitColumn(ColumnConfiguration1 configuration) {
        BitColumn column = new BitColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Boolean.valueOf(defVal));

        return column;
    }

    private static EnumColumn toEnumColumn(ColumnConfiguration1 configuration) {
        EnumColumn column = new EnumColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) column.setDefVal(defVal);

        column.setOptions(toOptions(configuration.getParams()));

        return column;
    }

    private static SetColumn toSetColumn(ColumnConfiguration1 configuration) {
        SetColumn column = new SetColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(defVal != null) {
            Set<String> set = new HashSet<>(Stream.of(defVal.split(",")).map(String::trim).toList());
            column.setDefVal(set);
        }

        column.setOptions(toOptions(configuration.getParams()));

        return column;
    }

    private static DateColumn toDateColumn(ColumnConfiguration1 configuration) {
        DateColumn column = new DateColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Date.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Date.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Date.valueOf(max));

        return column;
    }

    private static YearColumn toYearColumn(ColumnConfiguration1 configuration) {
        YearColumn column = new YearColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static DateTimeColumn toDateTimeColumn(ColumnConfiguration1 configuration) {
        DateTimeColumn column = new DateTimeColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(LocalDateTime.parse(defVal, FORMAT));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(LocalDateTime.parse(min, FORMAT));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(LocalDateTime.parse(max, FORMAT));

        return column;
    }

    private static TimestampColumn toTimestampColumn(ColumnConfiguration1 configuration) {
        TimestampColumn column = new TimestampColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Timestamp.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Timestamp.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Timestamp.valueOf(max));

        return column;
    }

    private static FileColumn toFileColumn(ColumnConfiguration1 configuration) {
        FileColumn column = new FileColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static ImageColumn toImageColumn(ColumnConfiguration1 configuration) {
        ImageColumn column = new ImageColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static AvatarColumn toAvatarColumn(ColumnConfiguration1 configuration) {
        AvatarColumn column = new AvatarColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static PasswordColumn toPasswordColumn(ColumnConfiguration1 configuration) {
        PasswordColumn column = new PasswordColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static SaltColumn toSaltColumn(ColumnConfiguration1 configuration) {
        SaltColumn column = new SaltColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static IconColumn toIconColumn(ColumnConfiguration1 configuration) {
        IconColumn column = new IconColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static QrCodeColumn toQrCodeColumn(ColumnConfiguration1 configuration) {
        QrCodeColumn column = new QrCodeColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static TinyBlobColumn toTinyBlobColumn(ColumnConfiguration1 configuration) {
        TinyBlobColumn column = new TinyBlobColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static BlobColumn toBlobColumn(ColumnConfiguration1 configuration) {
        BlobColumn column = new BlobColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static MediumBlobColumn toMediumBlobColumn(ColumnConfiguration1 configuration) {
        MediumBlobColumn column = new MediumBlobColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static LongBlobColumn toLongBlobColumn(ColumnConfiguration1 configuration) {
        LongBlobColumn column = new LongBlobColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Long.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Long.valueOf(max));

        return column;
    }

    private static BinaryColumn toBinaryColumn(ColumnConfiguration1 configuration) {
        BinaryColumn column = new BinaryColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static VarBinaryColumn toVarBinaryColumn(ColumnConfiguration1 configuration) {
        VarBinaryColumn column = new VarBinaryColumn();
        setBase(column, configuration);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static JsonColumn toJsonColumn(ColumnConfiguration1 configuration) {
        JsonColumn column = new JsonColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Long.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Long.valueOf(max));

        return column;
    }

    private static ColorColumn toColorColumn(ColumnConfiguration1 configuration) {
        ColorColumn column = new ColorColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    private static RefColumn toRefColumn(ColumnConfiguration1 configuration) {
        RefColumn column = new RefColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        return column;
    }

    private static YesnoColumn toYesnoColumn(ColumnConfiguration1 configuration) {
        YesnoColumn column = new YesnoColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        return column;
    }

    private static SexColumn toSexColumn(ColumnConfiguration1 configuration) {
        SexColumn column = new SexColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(defVal);

        return column;
    }

    private static AgeColumn toAgeColumn(ColumnConfiguration1 configuration) {
        AgeColumn column = new AgeColumn();
        setBase(column, configuration);

        String defVal = configuration.getDefVal();
        if(StrUtil.isNotBlank(defVal)) column.setDefVal(Integer.valueOf(defVal));

        String min = configuration.getMin();
        if(StrUtil.isNotBlank(min)) column.setMin(Integer.valueOf(min));

        String max = configuration.getMax();
        if(StrUtil.isNotBlank(max)) column.setMax(Integer.valueOf(max));

        return column;
    }

    @SuppressWarnings("unchecked")
    private static Map<String, String> toOptions(Map<String, Object> params) {
        if(params == null) ThrowKit.exception("必需配置【params.options】");

        Object obj = params.get("options");
        if(obj == null) ThrowKit.exception("必需配置【options】");

        if(obj instanceof Map) return (Map<String, String>) obj;

        if(obj instanceof String s) { // 形如：a=b, c=d
            Map<String, String> ret = new HashMap<>();
            for(String item: s.split(",")) {
                String[] keyValue = StrKit.cutInTwo(item.trim(), '=', false);
                ret.put(keyValue[0], keyValue[1]);
            }
            return ret;
        }

        if(obj.getClass().isArray()) {
            Map<String, String> ret = new HashMap<>();
            String[] items = (String[]) obj;
            for(String item: items) {
                String[] keyValue = StrKit.cutInTwo(item.trim(), '=', false);
                ret.put(keyValue[0], keyValue[1]);
            }
            return ret;
        }

        throw new RuntimeException("【params.options】格式错误");
    }
}
